package com.gh.ggkt.vod.controller;


import com.atguigu.ggkt.model.vod.Subject;
import com.gh.Result;
import com.gh.ggkt.vod.service.SubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Eric Fang
 * @since 2022-09-10
 */
@Slf4j
@RestController
@RequestMapping("/admin/vod/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    /**
     * 查询科目列表
     * @param id
     * @return
     */
    @GetMapping("listSubject/{id}")
    public Result listSubject(@PathVariable Long id){
        log.info("查询科目列表入参{}",id);
        List<Subject> subjectList = subjectService.listSubject(id);
        log.info("查询科目列表返参{}",subjectList);
        return Result.ok(subjectList);
    }

    /**
     * 课程分类导出
     */
    @GetMapping("exportExcelData")
    public void exportExcelData(HttpServletResponse response){
        subjectService.exportExcelData(response);
    }

    /**
     * 课程分类导入
     */
    @PostMapping("importExcel")
    public Result importExcel(MultipartFile file){
        subjectService.importExcel(file);
        return Result.ok(null).message("数据导入成功");
    }
}

